﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PresentationTier
{
    /// <summary>
    /// Partical ArtistForm class.
    /// </summary>
    public partial class ArtistsForm : Form
    {
        /*constants*/
        private const string ARTIST_NAME = "ArtistName";
        /*objects*/
        private BusinessLogicTier.ArtistsBLT ArtistsBLT;
        private BindingSource ArtistsBindingSource;

        /// <summary>
        /// Default constructor for ArtistForm.
        /// </summary>
        public ArtistsForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Set bindingsource and assign bindingsource to controls.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ArtistsForm_Load(object sender, EventArgs e)
        {
            this.ArtistsBLT = new BusinessLogicTier.ArtistsBLT();
            this.ArtistsBindingSource = new BindingSource();
            this.ArtistsBindingSource.DataSource = this.ArtistsBLT.GetArtists();
            this.artistsDataGridView.DataSource = this.ArtistsBindingSource;
            this.viewArtistsBindingNavigator.BindingSource = this.ArtistsBindingSource;
            this.delArtistsBindingNavigator.BindingSource = this.ArtistsBindingSource;
            this.artistNameListBox.DataSource = this.ArtistsBindingSource;
            this.artistNameListBox.DisplayMember = ARTIST_NAME;
        }

        /// <summary>
        /// InsertArtistsButton click event calls the insert method from the ArtistsBLT class.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InsertArtistButton_Click_1(object sender, EventArgs e)
        {
            /*insert event with paramter values from event textboxe controls*/
            this.ArtistsBLT.InsertArtist(artistNameTextBox.Text, artistAddressTextBox.Text, artistCityTextBox.Text,
                artistRegionTextBox.Text, artistPostalCodeTextBox.Text, artistCountryTextBox.Text, artistEmailTextBox.Text,
                artistPhoneTextBox.Text, artistFaxTextBox.Text);

            MessageBox.Show(artistNameTextBox.Text + " artist inserted.", "Insert Confirmation");

            /*reset bindingsource after insert has executed*/
            this.ArtistsBindingSource.DataSource = this.ArtistsBLT.GetArtists();
            this.ArtistsBindingSource.ResetBindings(true);

            /*clear all textbox controls*/
            this.artistAddressTextBox.Clear();
            this.artistCityTextBox.Clear();
            this.artistCountryTextBox.Clear();
            this.artistEmailTextBox.Clear();
            this.artistFaxTextBox.Clear();
            this.artistNameTextBox.Clear();
            this.artistPhoneTextBox.Clear();
            this.artistPostalCodeTextBox.Clear();
            this.artistRegionTextBox.Clear();
        }

        /// <summary>
        /// DeleteArtistButton click event calls the delete method from the ArtistsBLT class.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteArtistButton_Click(object sender, EventArgs e)
        {
            /*delete artist that user selected from the artistNameListbox control*/
            string artistId = this.artistsDataGridView.Rows[this.artistsDataGridView.CurrentRow.Index].Cells[0].Value.ToString();
            //this.ArtistsBLT.DeleteArtist(artistId);

            MessageBox.Show("Artist has been deleted.", "Delete Confirmation");

            /*reset bindingsource after insert has executed*/
            this.ArtistsBindingSource.DataSource = this.ArtistsBLT.GetArtists();
            this.ArtistsBindingSource.ResetBindings(true);
        }       
    }
}
